home *** CD-ROM | disk | FTP | other *** search
- /* LOCCounter.c -- window methods */
- /* Created 10/4/91 10:31 AM by AppMaker */
-
- /* This module overrides the AppMaker-generated code in zLOCCounter. */
- /* It provides a place for you to add your own code and still be able to */
- /* generate code for new changes to the user interface. This module will */
- /* not be regenerated by AppMaker unless you delete it. Its superclass, */
- /* zLOCCounter, may be regenerated to handle user interface changes */
- /* without losing your hand-coded changes to this module. */
-
- #include <CBureaucrat.h>
- #include <Commands.h>
- #include <TBUtilities.h>
- #include <DialogAids.h>
- #include "ResourceDefs.h"
- #include "LOCCounter.h"
-
- pascal int FileFilter ();
- pascal int dHook ();
- void SpinCursor ( void );
-
- extern Cursor waitCursor[6]; // cursors for spinning
- extern CBureaucrat *gGopher; // The current boss in the chain of command.
-
- long whichDir; // Dir ID to start looking in
- int whichVol; // Vol RefNum of same
- char name[40]; // scratch folder name
- char fname[40]; // current file name
- Str255 saveName; // save file name
- int vRef1, saveRef; // volume ref & file ref of save file
- int cursorCount; // what cursor were we on last time?
- SFReply frep; // Reply from file selector.
-
- TMetricData **metricData; // Metric information collected by the tool.
- Boolean analyzeSubdirectories = false; // True if subdirectories are to be analyzed as well.
-
- /*----------*/
- void CLOCCounter::ILOCCounter ( CDirector *aSupervisor )
-
- BEGIN
- inherited::ILOCCounter ( aSupervisor );
- itsGopher = this;
-
- // Get the previous metric data from the application's resource file.
-
- metricData = (TMetricData **) GetResource ( 'DATA', 128 );
- LoadResource ( metricData );
- HLock ( metricData );
-
- // Initialize the various window fields.
-
- this->IMetricFields ( *metricData );
-
- HUnlock ( metricData );
- END
-
- /*----------*/
- void CLOCCounter::IMetricFields ( TMetricData *data )
-
- BEGIN
- Str255 text;
-
- NumToString ( data->numLines, text );
- numLOCNowLabel->SetTextString ( text );
- NumToString ( data->numSemis, text );
- numSemicolonsNowLabel->SetTextString ( text );
- NumToString ( data->numClasses, text );
- numClassesNowLabel->SetTextString ( text );
-
- NumToString ( data->prevLines, text );
- numLOCPrevLabel->SetTextString ( text );
- NumToString ( data->prevSemis, text );
- numSemicolonsPrevLabel->SetTextString ( text );
- NumToString ( data->prevClasses, text );
- numClassesPrevLabel->SetTextString ( text );
-
- NumToString ( data->deltaLines, text );
- numLOCDeltaLabel->SetTextString ( text );
- NumToString ( data->deltaSemis, text );
- numSemicolonsDeltaLabel->SetTextString ( text );
- NumToString ( data->deltaClasses, text );
- numClassesDeltaLabel->SetTextString ( text );
- END
-
- /*----------*/
- /* Prompt the user on where to start indexing through folders to create the report */
-
- static Boolean GetStartDir ( void )
-
- BEGIN
- Point pt;
-
- whichDir = 0;
- whichVol = 0;
- FindDlogPosition( 'DLOG', getDlgID, &pt );
- SFGetFile ( pt, "\p", &FileFilter, 0, 0L, &dHook, &frep );
- return frep.good;
- END
-
- /*----------*/
- /* File filter for standard file. Always returns TRUE so only folders will be displayed. */
-
- static pascal int FileFilter ( void *Pparms )
-
- BEGIN
- return (-1);
- END
-
- /*----------*/
- /* Dialog hook routine so the "this folder" button will work */
-
- static pascal int dHook ( int item, DialogPtr dp )
-
- BEGIN
- IF item == 11 THEN
- whichDir = CurDirStore;
- whichVol = SFSaveDisk * -1;
- frep.good = true;
- return(3);
-
- ELSIF item == 13 THEN
- analyzeSubdirectories = NOT analyzeSubdirectories;
- SetCheckbox ( 13, analyzeSubdirectories );
-
- END_IF;
- return(item);
- END
-
- /*----------*/
- /* Put up the next cursor */
-
- static void SpinCursor ( void )
-
- BEGIN
- if (++cursorCount > 5) cursorCount = 0;
- SetCursor( &waitCursor[cursorCount] );
- END
-
- /*----------*/
- void CLOCCounter::AnalyzeFile ( long dirID, TMetricData *data )
-
- BEGIN
- int fileRefNum;
- long bytes;
- char buffer[256];
- int handDelay;
- const int initHandDelay = 100;
-
- // Perform metric calculations.
-
- IF NOT HOpen ( whichVol, dirID, fname, fsRdPerm, &fileRefNum ) THEN
-
- // Increment the files counter.
-
- data->numClasses++;
-
- // Test the contents of the file.
-
- handDelay = initHandDelay;
- bytes = 1;
- WHILE FSRead ( fileRefNum, &bytes, &buffer ) == noErr LOOP
-
- // Provide feedback that something is happening.
-
- IF NOT --handDelay THEN
- handDelay = initHandDelay;
- SpinCursor();
- END_IF;
-
- // Test for line terminator.
-
- IF buffer[0] == '\r' THEN
- data->numLines++;
- END_IF;
-
- // Test for semicolon.
-
- IF buffer[0] == ';' THEN
- data->numSemis++;
- END_IF;
-
- END_LOOP;
- FSClose ( fileRefNum );
- END_IF;
- END
-
- /*----------*/
- void CLOCCounter::AnalyzeDirectory ( long dirID, int index, TMetricData *data )
-
- BEGIN
- CInfoPBRec myParam;
-
- // Analyze the contents of the files within the directory.
-
- WHILE true LOOP
- myParam.dirInfo.ioCompletion = 0;
- myParam.dirInfo.ioNamePtr = (StringPtr) &fname;
- myParam.dirInfo.ioVRefNum = whichVol;
- myParam.dirInfo.ioDrDirID = dirID;
- myParam.dirInfo.ioFDirIndex = index++;
- if (PBGetCatInfo(&myParam, 0)) break;
- IF (myParam.dirInfo.ioFlAttrib & 16) AND analyzeSubdirectories THEN
- this->AnalyzeDirectory ( myParam.dirInfo.ioDrDirID, 1, data );
- ELSIF fname[fname[0]-1] == '.' AND
- (fname[fname[0]] == 'c' OR
- fname[fname[0]] == 'C' OR
- fname[fname[0]] == 'h' OR
- fname[fname[0]] == 'H') THEN
- this->AnalyzeFile ( dirID, data );
- END_IF;
- END_LOOP;
- END
-
- /*----------*/
- void CLOCCounter::CountMetrics ( long dirID, int index )
-
- BEGIN
- TMetricData *data;
-
- // Initialize the metric information.
-
- LoadResource ( metricData );
- HLock ( metricData );
- data = *metricData;
- data->numClasses = 0;
- data->numLines = 0;
- data->numSemis = 0;
-
- // Analyze the contents of the files.
-
- this->AnalyzeDirectory ( dirID, 1, data );
-
- // Compute the difference between the current metrics and the previous.
-
- IF data->metricsBaselined THEN
- data->deltaClasses = data->numClasses - data->prevClasses;
- data->deltaLines = data->numLines - data->prevLines;
- data->deltaSemis = data->numSemis - data->prevSemis;
- END_IF;
-
- // Update the display.
-
- this->IMetricFields ( data );
-
- HUnlock ( metricData );
- ChangedResource ( metricData );
- WriteResource ( metricData );
- END
-
- /*----------*/
- void CLOCCounter::DoCommand ( long theCommand )
-
- BEGIN
- Str255 text;
-
- switch (theCommand) {
-
- case cmdSelectFolder:
- BEGIN
- IF GetStartDir () THEN
- CountMetrics ( whichDir, 1);
- END_IF;
- END;
- break;
-
- case cmdBaselineMetrics:
- BEGIN
- TMetricData *data;
-
- LoadResource ( metricData );
- HLock ( metricData );
- data = *metricData;
-
- data->prevClasses = data->numClasses;
- data->deltaClasses = 0;
- data->prevLines = data->numLines;
- data->deltaLines = 0;
- data->prevSemis = data->numSemis;
- data->deltaSemis = 0;
- data->metricsBaselined = true;
-
- this->IMetricFields ( data );
-
- HUnlock ( metricData );
- ChangedResource ( metricData );
- WriteResource ( metricData );
- END;
- break;
-
- default:
- inherited::DoCommand (theCommand);
- break;
- }
-
- }
-